package com.qall.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;

public class LOGUtil {
    public static Logger getLog() {

        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
        Class<?> classParent = null;
        try {
            classParent = Class.forName(stackTraceElements[2].getClassName());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return LoggerFactory.getLogger(classParent);
    }


    public static String getStackTraceInfo(Exception e) {

        StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            e.printStackTrace(pw);//将出错的栈信息输出到printWriter中
            pw.flush();
            sw.flush();

            return sw.toString();
        } catch (Exception ex) {

            return "error in logger exception";
        } finally {
            if (sw != null) {
                try {
                    sw.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            if (pw != null) {
                pw.close();
            }
        }

    }
}
